#ifndef _GAME_H
#define _GAME_H


#include <memory>
#include <iostream>
#include <stack>
#include "MenuFactory.h"
#include "CONST.h"

class IMenuComponent;

class Game {
public:
    inline void init();

    inline void run();

    inline void term();


private:
    std::shared_ptr<IMenuComponent> menu;

};

inline void Game::init() {
    MenuFactory *factory = new myMenuFactory;
    menu = std::shared_ptr<IMenuComponent>(factory->createMenu());
}

inline void Game::run() {
    menu->show();

}

inline void Game::term() {
    IMenuComponent *item;
    int selected;
    item = menu.get();
    std::stack<IMenuComponent*> stack;
    while (std::cin >> selected) {
        switch (item->checkType(selected)){
            case ISNODE:
                stack.push(item);
                item = item->getchilden().at(selected).get();
                break;
            case ISBACK:
                item=stack.top();
                stack.pop();
                item->show();
                break;
            case ISLEAF:
                //TODO 这里处理具体选项
            std::cout<<"这是一个选项。。"<<std::endl;
                item->show();

                break;
        }

    }


}

#endif
